package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TCarousel;
import com.ruoyi.system.service.ITCarouselService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP轮播图Controller
 *
 * @author zhaohs
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/system/carousel")
public class TCarouselController extends BaseController {
    private String prefix = "system/carousel";

    @Autowired
    private ITCarouselService tCarouselService;

    @RequiresPermissions("system:carousel:view")
    @GetMapping()
    public String carousel() {
        return prefix + "/carousel";
    }

    /**
     * 查询APP轮播图列表
     */
    @RequiresPermissions("system:carousel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TCarousel tCarousel) {
        startPage();
        List<TCarousel> list = tCarouselService.selectTCarouselList(tCarousel);
        return getDataTable(list);
    }

    /**
     * 导出APP轮播图列表
     */
    @RequiresPermissions("system:carousel:export")
    @Log(title = "APP轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TCarousel tCarousel) {
        List<TCarousel> list = tCarouselService.selectTCarouselList(tCarousel);
        ExcelUtil<TCarousel> util = new ExcelUtil<TCarousel>(TCarousel. class);
        return util.exportExcel(list, "carousel");
    }

    /**
     * 新增APP轮播图
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存APP轮播图
     */
    @RequiresPermissions("system:carousel:add")
    @Log(title = "APP轮播图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TCarousel tCarousel) {
        return toAjax(tCarouselService.insertTCarousel(tCarousel));
    }

    /**
     * 修改APP轮播图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TCarousel tCarousel =tCarouselService.selectTCarouselById(id);
        mmap.put("tCarousel", tCarousel);
        return prefix + "/edit";
    }

    /**
     * 修改保存APP轮播图
     */
    @RequiresPermissions("system:carousel:edit")
    @Log(title = "APP轮播图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TCarousel tCarousel) {
        return toAjax(tCarouselService.updateTCarousel(tCarousel));
    }

    /**
     * 删除APP轮播图
     */
    @RequiresPermissions("system:carousel:remove")
    @Log(title = "APP轮播图", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tCarouselService.deleteTCarouselByIds(ids));
    }
}
